import 'dart:math';

import 'package:flutter/material.dart';
import 'package:jicaimao_flutter/entity/account_bean.dart';
import 'package:jicaimao_flutter/utils/toast.dart';
import 'package:jicaimao_flutter/widget/gradient_circular_progress.dart';
import 'package:jicaimao_flutter/widget/turn_box.dart';

class BidWattingDetails extends StatefulWidget {
  List<AccountBeanResult> list;

  @override
  _BidWattingDetailsState createState() => _BidWattingDetailsState();

//  BidWattingDetails(
//    this.list,
//  );
}

class _BidWattingDetailsState extends State<BidWattingDetails>
    with TickerProviderStateMixin {
  AnimationController _animationController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    _animationController =
        new AnimationController(vsync: this, duration: Duration(seconds: 3));
    bool isForward = true;
    _animationController.addStatusListener((status) {
      if (status == AnimationStatus.forward) {
        isForward = true;
      } else if (status == AnimationStatus.completed ||
          status == AnimationStatus.dismissed) {
        if (isForward) {
          _animationController.reverse();
        } else {
          _animationController.forward();
        }
      } else if (status == AnimationStatus.reverse) {
        isForward = false;
      }
    });
    _animationController.forward();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Color(0xFFF6F5F5),
        appBar: AppBar(
          centerTitle: true,
          backgroundColor: Colors.white,
          leading: IconButton(
            icon: Icon(
              Icons.arrow_back_ios,
              color: Colors.grey,
            ),
            onPressed: () => Navigator.pop(context),
          ),
          title: Text(
            '投标',
            style: TextStyle(
              fontSize: 16,
              color: Colors.black,
            ),
          ),
        ),
        body: Container(
          margin: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 0.0),
          child: Column(
            children: <Widget>[
              Expanded(
                child: Container(
                  child: Column(
                    children: <Widget>[
                      Stack(
                        children: <Widget>[
                          ///进度条
                          _ProgressBar(context),
                          _Days(context),
                          new Positioned(
                            left: 167.2,
                            top: 129.0,
                            child: Text(
                              '定期',
                              style: TextStyle(color: Color(0xFF333333)),
                            ),
                          ),
                        ],
                      ),
                      new Divider(
                        height: 12,
                        color: Color(0xFFF6F5F5),
                      ),
                      commentTitle(context, '积分数量（BSC）', "200.000.0000", " "),
                      commentTitle(
                          context, '申购时间 ', "2018-06-02 15:23:00", " "),
                      commentTitle(context, '到期时间', "2018-06-02 15:23:00", " "),
                      commentTitle(context, '福利(BSC)', "210.0000", " "),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
        bottomNavigationBar: GestureDetector(
          child: Container(
            margin: EdgeInsets.only(bottom: 0.3),
            height: 50.0,
            color: Color(0xFFAD5AFE),
            child: Center(
              child: Text(
                '领取福袋',
                style: TextStyle(
                  fontSize: 15,
                  color: Colors.white,
                ),
              ),
            ),
          ),
          onTap: (){
            Toast.toast(context, '找有喜要！');
          },
        ),

      ),
    );
  }

  ///进度条
  Widget _ProgressBar(BuildContext context) {
    return Container(
      color: Colors.white,
      padding: const EdgeInsets.only(bottom: 18.0, right: 50),
      child: Wrap(spacing: 10.0, runSpacing: 16.0, children: <Widget>[
        ClipRect(
          child: Align(
            alignment: Alignment.topCenter,
            heightFactor: .8,
            child: Padding(
              padding: const EdgeInsets.only(bottom: 8.0),
              child: SizedBox(
                width: 120.0,
                height: 163.0,
                child: TurnBox(
                  turns: .60,
                  child: GradientCircularProgressIndicator(
                    colors: [Color(0xFFAD5AFE), Color(0xFFE165C7)],
                    radius: 55.0,
                    stokeWidth: 4.0,
                    value: _animationController.value,
                    totalAngle: 1.6 * pi,
                    strokeCapRound: true,
                  ),
                ),
              ),
            ),
          ),
        ),
      ]),
    );
  }

  Widget _Days(BuildContext context) {
    return Positioned(
      left: 160.2,
      top: 87.0,
      child: Text(
        '180天',
        style: TextStyle(color: Color(0xFFB75CF4)),
      ),
    );
  }

  Widget commentTitle(
      BuildContext context, String title, String content, String img) {
    return Container(
      height: 45.0,
      padding: EdgeInsets.fromLTRB(10.0, 0.0, 10.0, 0.0),
      margin: EdgeInsets.fromLTRB(0.0, 1.0, 0.0, 0.0),
      color: Colors.white,
      child: Row(
        children: <Widget>[
          Expanded(
            child: Container(
              alignment: Alignment.centerLeft,
              child: Text(title,
                  style: new TextStyle(
                      fontWeight: FontWeight.normal,
                      fontSize: 15.0,
                      color: Color(0xFF777777))),
            ),
          ),
          new Image.asset(
            img,
            width: 5.0,
            height: 5.0,
          ),
          Expanded(
            child: Container(
              alignment: Alignment.centerRight,
              child: new Text(content,
                  style: new TextStyle(
                      fontWeight: FontWeight.normal,
                      fontSize: 15.0,
                      color: Color(0xFF333333))),
            ),
          ),
        ],
      ),
    );
  }
}
